package com.htthorizon.model.controller;

import com.htthorizon.common.core.constant.Constants;
import com.htthorizon.common.core.web.controller.BaseController;
import com.htthorizon.common.core.web.domain.AjaxResult;
import com.htthorizon.common.core.web.page.TableDataInfo;
import com.htthorizon.common.log.annotation.Log;
import com.htthorizon.common.log.enums.BusinessType;
import com.htthorizon.common.security.annotation.RequiresPermissions;
import com.htthorizon.model.request.ModelCrossAuditAddReq;
import com.htthorizon.model.request.ModelCrossAuditSearchReq;
import com.htthorizon.model.response.ModelCrossAuditVo;
import com.htthorizon.model.service.IModelCrossAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author Brilliant
 */
@RestController
@RequestMapping("/crossAudit")
public class ModelCrossAuditController extends BaseController {

    @Autowired
    private IModelCrossAuditService modelCrossAuditService;

    @GetMapping("/list")
    @RequiresPermissions("system:cross:audit")
    @Log(title = "系统管理/交叉审计管理", businessType = BusinessType.QUERY)
    public TableDataInfo list(@Valid  ModelCrossAuditSearchReq modelCrossAuditSearchReq){
        TableDataInfo tableDataInfo = new TableDataInfo();

      int count=  modelCrossAuditService.getCount(modelCrossAuditSearchReq);
      tableDataInfo.setTotal(count);
      tableDataInfo.setCode(200);
       List<ModelCrossAuditVo> list = modelCrossAuditService.getList(modelCrossAuditSearchReq);
       tableDataInfo.setRows(list);
       return tableDataInfo;
    }

    @PostMapping("/add")
    @RequiresPermissions("system:cross:audit")
    @Log(title = "系统管理/交叉审计管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody ModelCrossAuditAddReq modelCrossAuditAddReq){
        return toAjax(modelCrossAuditService.add(modelCrossAuditAddReq));
    }

    @PostMapping("/edit")
    @RequiresPermissions("system:cross:audit")
    @Log(title = "系统管理/交叉审计管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody ModelCrossAuditAddReq modelCrossAuditAddReq){
        return toAjax(modelCrossAuditService.edit(modelCrossAuditAddReq));
    }

    @PostMapping("/del/{id}")
    @RequiresPermissions("system:cross:audit")
    @Log(title = "系统管理/交叉审计管理", businessType = BusinessType.DELETE)
    public AjaxResult del(@PathVariable("id") Long id){
        return toAjax(modelCrossAuditService.del(id));
    }

}
